package cate.common.table.activity.restrictcall.row;

import cate.common.annotation.SplitParse;
import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.table.item.hero.StarGroupList;
import cate.common.util.SplitParser;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@EExcelRowClass
public class RestrictCallBaseRow extends ERow {
    @EExcelNoteField(fieldName = "配置ID")
    public int configId;
    @EExcelNoteField(fieldName = "本期推荐")
    public String sellStr;
    @EExcelNoteField(fieldName = "消耗元宝次数",defaultValue = "0")
    public int m1Limit;
    @EExcelNoteField(fieldName = "召唤次数奖励分组")
    public int callRewardGroup;
    @EExcelNoteField(fieldName = "免费次数上限",defaultValue = "1")
    public int freeLimit;
    @EExcelNoteField(fieldName = "正常召唤组")
    public String normalGroup;
    @EExcelNoteField(fieldName = "十连最多出稀有个数",defaultValue = "0")
    public int luckyLimit;
    @EExcelNoteField(fieldName = "防脸白召唤组")
    public int unluckyGroup;
    @EExcelNoteField(fieldName = "不幸次数上限",defaultValue = "0")
    public int unluckyLimit;
    @EExcelNoteField(fieldName = "幸运召唤组")
    public int luckyGroup;
    @EExcelNoteField(fieldName = "分组")
    public int group;
    @EExcelNoteField(fieldName = "召唤类型")
    public int callType;
    @EExcelNoteField(fieldName = "每日召唤次数上限",defaultValue = "-1")
    public int dailyLimit;
    @EExcelNoteField(fieldName = "召唤模式",defaultValue = "0")
    public byte mode;
    @EExcelNoteField(fieldName = "跑马灯公告",defaultValue = "0")
    public int lampId;
    @EExcelNoteField(fieldName = "更换奖励组")
    public String exchange;
    @EExcelNoteField(fieldName = "更换次数",defaultValue = "0")
    public int exchangeLimit;
    /**
     * 推荐奖励权重保底次数列表
     */
    public List<PickSellParam> pickSellParams;

    public List<PickSellParam> exchangeParams;

    @NoteClass(value = "自选up奖励权重配置")
    public static final class PickSellParam {
        @SplitParse(order = 0)
        public int sellTid;

        @SplitParse(order = 1, defaultValue = "1")
        public double weight;

        @SplitParse(order = 2, defaultValue = "120")
        public int guarantee;
    }

    public PickSellParam getParam(int id) {
        return pickSellParams.stream().filter(param -> param.sellTid == id).findAny().orElse(null);
    }

    public PickSellParam getExchangeParam(int id) {
        return exchangeParams.stream().filter(param -> param.sellTid == id).findAny().orElse(null);
    }

    @JsonIgnore
    public StarGroupList config = new StarGroupList();

    @Override
    public void decode() {
        pickSellParams = new ArrayList<>();
        if (StringUtils.isNotBlank(this.sellStr)) {
            this.pickSellParams = SplitParser.parse(PickSellParam.class, this.sellStr);
        }
        exchangeParams = new ArrayList<>();
        if (StringUtils.isNotBlank(this.exchange)) {
            this.exchangeParams = SplitParser.parse(PickSellParam.class, this.exchange);
        }
        config.parse(normalGroup);
    }

}




